#include "include.h"

UINT8 sendbuf[BUFFER_SIZE] = {0};

void packageinit_head( UINT8 *sendbuf )
{
    sendbuf[0] = 0x55;
    sendbuf[1] = 0xAA;
    sendbuf[2] = 0x00;
    sendbuf[3] = 0x00;
}
void package_ending( UINT8* target_buf, UINT8* sources_buf, UINT16* len )
{
    sources_buf[(*len)++] = 0xAA;
    sources_buf[(*len)++] = 0x55;
    sources_buf[4] = *len;
    sources_buf[5] = *len >> 8;
    memset(target_buf, 0,BUFFER_SIZE );
    memcpy(target_buf, sources_buf, *len);

}

void handle_tcp_recv_data(UCHAR* data)
{
	switch(data[6])
	{		
		case Type_Gpio:
			if( data[7] == 0xFF )
			{
				io_control(1);
			}
			else if( data[7] == 0x00 )
			{
				io_control(2);			
			}
			else if( data[7] == 0x55 )
			{
				io_control(3);			
			}
			else if( data[7] == 0xAA )
			{
				io_control(4);			
			}
			break;
			
		case Type_Adda:
			dac_set_value( data + 7 );
			break;
			
		default : break;
	}
}



